const formatTime = (time,format = 'Y-M-D h:m:s',title)=>{
	if (!time) return title|| ''
    var formateArr = ['Y', 'M', 'D', 'h', 'm', 's'];
    var returnArr = [];

    var date = new Date(time);
    returnArr.push(date.getFullYear());
    returnArr.push(formatNumber(date.getMonth() + 1));
    returnArr.push(formatNumber(date.getDate()));

    returnArr.push(formatNumber(date.getHours()));
    returnArr.push(formatNumber(date.getMinutes()));
    returnArr.push(formatNumber(date.getSeconds()));
    for (var i in returnArr) {
        format = format.replace(formateArr[i], returnArr[i]);
    }
    return format;
}

//数据转化
function formatNumber(n) {
    n = n.toString()
    return n[1] ? n : '0' + n
}

// 转换时分秒
const timings = function(time){
    // 小时
    let Y = Math.floor(time/60/60)
    if(Y>0){
        time = time-Y*1800
    }
    // 分钟
    let M = Math.floor(time/60)
    if(M>0){
        time = time-M*60
    }
    Y = repair(Y)
    M = repair(M)
    return `${Y}:${M}:${repair(time)}`
}
// 补0
function repair(time){
    return time>9?time:`0${time}`
}

export {
    formatTime,
    timings
}